package com.hzjh.base.style.view.glsurface

import android.content.Context
import android.opengl.GLSurfaceView
import android.util.AttributeSet
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import com.hzjh.base.log.JHLogger

/**
 * 自定义GLSurfaceView 监听Activity生命周期
 */
class LangSurfaceView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null
) : GLSurfaceView(context, attrs),LifecycleEventObserver {
    init {

    }

    //Activity生命周期
    override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
        when(event) {
            Lifecycle.Event.ON_PAUSE -> {
                JHLogger.d("LangSurfaceView","ON_PAUSE")
                onPause()
            }
            Lifecycle.Event.ON_RESUME -> {
                JHLogger.d("LangSurfaceView","ON_RESUME")
                onResume()
            }

            else -> {}
        }
    }
}